<?php
class FrbMessageClientController extends DooController
{

  private $content;

  private $phone='';

  private $mail='';

  private $sender;

  public function __construct() {

  }

  public function store() {
    if (!empty($this->content) && !empty($this->sender) && (!empty($this->mail) || !empty($this->phone))) {
      Doo::loadModelAt('FrbMessage', 'frbMessage');
      $message = new FrbMessage();
      $message->mes_mail = $this->mail;
      $message->mes_flag = 1;
      $message->mes_mes = $this->content;
      $message->mes_nom = $this->sender;
      $message->mes_tel = $this->phone;
      Doo::loadCore('db/DooDbExpression');
      $message->mes_date = new DooDbExpression('NOW()');
      $this->db()->insert($message);
      return true;
    }
    return false;
  }

  public function setContent($content) {
    $this->content = $this->Valid($content);
  }

  public function setPhone($phone) {
    $this->phone = $this->Valid($phone);
  }

  public function setMail($mail) {
    $this->mail = $this->Valid($mail);
  }

  public function setSender($sender) {
    $this->sender = $this->Valid($sender);
  }
  
  /**
   * 
   * Transforme le contenu pour éviter les injections de code
   * @param String $token à transformer
   * @return le $token fiable
   */
  private function Valid($token) {
    return htmlspecialchars($token);
  }


}